package com.putprize.semantic.service;


import org.apache.thrift.TException;

import com.putprize.semantic.SemanticNerer;

import java.util.Map;
import java.util.HashMap;


public class NerProcessThriftImpl implements DocumentProcessThrift.Iface {

    private SemanticNerer ner;

    public  NerProcessThriftImpl(SemanticNerer ner){
        this.ner = ner;
    }

    @Override
    public Map<String,String> process(Map<String,String> data) throws TException {

        String title = "";
        if (data.containsKey("cut_title")){
            title = data.get("cut_title");
        }
        String content = "";
        if (data.containsKey(("cut_content"))){
            content = data.get("cut_content");
        }

        String ner_title = ner.process(title);
        String[] split_content = content.split("\n");
        StringBuilder ner_content = new StringBuilder();
        for (String line: split_content){
            ner_content.append(ner.process(line)).append("\n");
        }

        Map<String,String> res_map = new HashMap<String,String>();
        res_map.put("ner_title",ner_title);
        res_map.put("ner_content",ner_content.toString().trim());

        return res_map;

    }

}
